using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Utility;
using Entities;
using BUS;
using DAL;

public partial class admin_danhsachdonhang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }

    }
    private void LoadData()
    {
        int total = 5;
        Criteria cri = new Criteria();
        //hyperlinkPager.PageSize = int.Parse(ConfigurationManager.AppSettings["pagesize"]);
        Repeater1.DataSource = tbDonHangBUS.Get(cri.Criter, hyperlinkPager.CurrentIndex,
        hyperlinkPager.PageSize, tbDonHangColumns.MaDH .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataBind();
        hyperlinkPager.ItemCount = total;
        if (hyperlinkPager.ItemCount <= hyperlinkPager.PageSize)
            hyperlinkPager.Visible = false;
        else
            hyperlinkPager.Visible = true;
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
        e.Item.ItemType == ListItemType.Item)
        {
            tbDonHang donhang = (tbDonHang)e.Item.DataItem;
            tbKhachHang khachhang = tbKhachHangBUS.GetByID(donhang.MaKH );
            if (khachhang != null)
            {
                Literal lit_KhachHang = (Literal)e.Item.FindControl("lit_KhachHang");
                lit_KhachHang.Text = khachhang.TenKH;
            }
            
            tbTrangThai trangthai = tbTrangThaiBUS.GetByID(donhang.TrangThai );
            if (trangthai != null)
            {
                Literal lit_TrangThai = (Literal)e.Item.FindControl("lit_TrangThai");
                lit_TrangThai.Text = trangthai.Ten ;
            }
            
            tbHinhThucThanhToan hinhthuctt = tbHinhThucThanhToanBUS.GetByID(donhang.HinhThucTT );
            if (hinhthuctt != null)
            {
                Literal lit_Hinhthuctt = (Literal)e.Item.FindControl("lit_Hinhthuctt");
                lit_Hinhthuctt.Text = hinhthuctt .TenThanhToan ;
            }
            HyperLink hyp_DonHang = (HyperLink)e.Item.FindControl("hyp_DonHang");
            hyp_DonHang.Text = donhang.MaDH .ToString();
            hyp_DonHang.NavigateUrl = "~/Admin/Chitietdonhang.aspx?id=" + donhang.MaDH .ToString();
        }
    }

    protected void hyperlinkPager_Command(object sender, CommandEventArgs e)
    {
        hyperlinkPager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
}
